package com.vadmin.vadminjava.service;

import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;


/* ***********************************************************
 *
 * 微信的卡劵：客户端前端专用的
 *
 * **********************************************************/
@Component
public class WxCouponClientService extends CommonExtends{

    org.slf4j.Logger logger = LoggerFactory.getLogger(WxCouponClientService.class.getName());


    /**
     * 读取商家券列表
     * @param params
     * @return
     */
    public JSONObject wxCouponBusinessList(JSONObject params) {

        String table  = "wx_coupon";//数据库表
        String conditions = "";//条件

        //参数处理
        String  transactionMinimum = params.getString("transactionMinimum");
        if(StringUtils.isNoneEmpty(transactionMinimum)){
            conditions += " AND transaction_minimum >= '" + transactionMinimum + "' ";
        }

        return commonDataListFlexible(table,conditions,params);
    }

    /**
     * 读取商家券详情
     * @param params
     * @return
     */
    public JSONObject couponDetailOfBusiness(JSONObject params){

        JSONObject map = new JSONObject();
        map.put("resultFlag",false);
        map.put("resultMsg","读取失败 ");

        //参数
        String stockId = params.getString("stockId");

        if(StringUtils.isEmpty(stockId)){
            map.put("resultMsg","读取失败，缺少券id参数");
            return map;
        }else{
            //参数条件处理
            String sql = "select * from wx_coupon where stock_id = '"+stockId+"'";
            return commonDataSingle(sql);
        }


    }


}
